package cn.jjxx.shiro.httpclient;

import cn.jjxx.shiro.httpclient.utils.HttpUtil;

public class Client
{
  public static Response execute(Request request)
    throws Exception
  {
    switch (request.getMethod().ordinal()) {
    case 1:
      return HttpUtil.httpGet(request.getHost(), request.getPath(), request
        .getTimeout(), request
        .getHeaders(), request
        .getQuerys(), request
        .getSignHeaderPrefixList(), request
        .getAppKey(), request.getAppSecret());
    case 2: 
      return HttpUtil.httpPost(request.getHost(), request.getPath(), request
        .getTimeout(), request
        .getHeaders(), request
        .getQuerys(), request
        .getBodys(), request
        .getSignHeaderPrefixList(), request
        .getAppKey(), request.getAppSecret()); 
    case 5:
      return HttpUtil.httpPost(request.getHost(), request.getPath(), request
        .getTimeout(), request
        .getHeaders(), request
        .getQuerys(), request
        .getStringBody(), request
        .getSignHeaderPrefixList(), request
        .getAppKey(), request.getAppSecret());
    case 6: 
      return HttpUtil.httpPost(request.getHost(), request.getPath(), request
        .getTimeout(), request
        .getHeaders(), request
        .getQuerys(), request
        .getBytesBody(), request
        .getSignHeaderPrefixList(), request
        .getAppKey(), request.getAppSecret());
    case 8:
      return HttpUtil.httpPut(request.getHost(), request.getPath(), request
        .getTimeout(), request
        .getHeaders(), request
        .getQuerys(), request
        .getStringBody(), request
        .getSignHeaderPrefixList(), request
        .getAppKey(), request.getAppSecret());
    case 9:
      return HttpUtil.httpPut(request.getHost(), request.getPath(), request
        .getTimeout(), request
        .getHeaders(), request
        .getQuerys(), request
        .getBytesBody(), request
        .getSignHeaderPrefixList(), request
        .getAppKey(), request.getAppSecret());
    case 10:
      return HttpUtil.httpDelete(request.getHost(), request.getPath(), request
        .getTimeout(), request
        .getHeaders(), request
        .getQuerys(), request
        .getSignHeaderPrefixList(), request
        .getAppKey(), request.getAppSecret());
    }
    throw new IllegalArgumentException(String.format("unsupported method:%s", new Object[] { request.getMethod() }));
  }
}